﻿namespace WMS6.SQLServerDAL
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Common;
    using System.Data.SqlClient;
    using WMS6.Common;
    using WMS6.DataEntity;
    using WMS6.DBUtility;
    using WMS6.IDAL;
    using WMS6.QueryEntity;

    public class UdfReportSettingDetailDA : IUdfReportSettingDetailDA
    {
        private string CREATED_BY = "@CREATED_BY";
        private string CTRL_ID = "@CTRL_ID";
        private string CTRL_LABEL = "@CTRL_LABEL";
        private string CTRL_TYPE = "@CTRL_TYPE";
        private string DEFAULT_VALUE = "@DEFAULT_VALUE";
        private string IS_MUST_INPUT = "@IS_MUST_INPUT";
        private string LINE_ID = "@LINE_ID";
        private string PARAM_NAME = "@PARAM_NAME";
        private string REPORT_ID = "@REPORT_ID";
        private string SQL_CHECK_UDF_REPORT_SETTING_DETAIL_ID_UNIQUE = " SELECT COUNT(1) FROM @_@UDF_REPORT_SETTING_DETAIL WHERE REPORT_ID = @REPORT_ID AND LINE_ID = @LINE_ID ";
        private string SQL_DELETE_ONE_UDF_REPORT_SETTING_DETAIL = " DELETE FROM @_@UDF_REPORT_SETTING_DETAIL WHERE REPORT_ID = @REPORT_ID AND LINE_ID = @LINE_ID ";
        private string SQL_DELETE_UDF_REPORT_SETTING_DETAIL = " DELETE FROM @_@UDF_REPORT_SETTING_DETAIL WHERE REPORT_ID = @REPORT_ID ";
        private string SQL_INSERT_UDF_REPORT_SETTING_DETAIL = " INSERT INTO @_@UDF_REPORT_SETTING_DETAIL ([WH_ID] ,[REPORT_ID] ,[LINE_ID] ,[CTRL_ID] ,[CTRL_LABEL] ,[CTRL_TYPE] ,[DEFAULT_VALUE] ,[PARAM_NAME] ,[IS_MUST_INPUT] ,[UDF1] ,[UDF2] ,[UDF3] ,[UDF4] ,[UDF5] ,[CREATED_BY] ,[CREATED_DATE] ,[UPDATED_BY] ,[UPDATED_DATE])  VALUES (@WH_ID ,@REPORT_ID ,@LINE_ID ,@CTRL_ID ,@CTRL_LABEL ,@CTRL_TYPE ,@DEFAULT_VALUE ,@PARAM_NAME ,@IS_MUST_INPUT ,@UDF1 ,@UDF2 ,@UDF3 ,@UDF4 ,@UDF5 ,@CREATED_BY ,GETDATE() ,@UPDATED_BY ,GETDATE()) ";
        private string SQL_SELECT_ALL_UDF_REPORT_SETTING_DETAIL = " SELECT [ROWID] ,[WH_ID] ,[REPORT_ID] ,[LINE_ID] ,[CTRL_ID] ,[CTRL_LABEL] ,[CTRL_TYPE] ,[DEFAULT_VALUE] ,[PARAM_NAME] ,[IS_MUST_INPUT] ,[UDF1] ,[UDF2] ,[UDF3] ,[UDF4] ,[UDF5] ,[CREATED_BY] ,[CREATED_DATE] ,[UPDATED_BY] ,[UPDATED_DATE] FROM @_@UDF_REPORT_SETTING_DETAIL ";
        private string SQL_UPDATE_UDF_REPORT_SETTING_DETAIL = " UPDATE @_@UDF_REPORT_SETTING_DETAIL SET [WH_ID] = @WH_ID ,[REPORT_ID] = @REPORT_ID ,[LINE_ID] = @LINE_ID ,[CTRL_ID] = @CTRL_ID ,[CTRL_LABEL] = @CTRL_LABEL ,[CTRL_TYPE] = @CTRL_TYPE ,[DEFAULT_VALUE] = @DEFAULT_VALUE ,[PARAM_NAME] = @PARAM_NAME ,[IS_MUST_INPUT] = @IS_MUST_INPUT ,[UDF1] = @UDF1 ,[UDF2] = @UDF2 ,[UDF3] = @UDF3 ,[UDF4] = @UDF4 ,[UDF5] = @UDF5 ,[CREATED_BY] = @CREATED_BY ,[CREATED_DATE] = GETDATE() ,[UPDATED_BY] = @UPDATED_BY ,[UPDATED_DATE] = GETDATE()  WHERE REPORT_ID = @REPORT_ID AND LINE_ID = @LINE_ID ";
        private string UDF1 = "@UDF1";
        private string UDF2 = "@UDF2";
        private string UDF3 = "@UDF3";
        private string UDF4 = "@UDF4";
        private string UDF5 = "@UDF5";
        private string UPDATED_BY = "@UPDATED_BY";
        private string WH_ID = "@WH_ID";

        public bool CheckUdfReportSettingDetailIDUnique(string reportID, string LineID, string whLoginID)
        {
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@REPORT_ID", reportID), new SqlParameter("@LINE_ID", LineID) };
            return (DBHelper.ExecuteScalar(CommandType.Text, this.SQL_CHECK_UDF_REPORT_SETTING_DETAIL_ID_UNIQUE.Replace("@_@", whLoginID), paras).ToString() == "1");
        }

        public bool CheckUdfReportSettingDetailIDUnique(DataBase dataBase, DbTransaction tran, string reportID, string lineID, string whLoginID)
        {
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@REPORT_ID", reportID), new SqlParameter("@LINE_ID", lineID) };
            return (dataBase.ExecuteScalar(tran, CommandType.Text, this.SQL_CHECK_UDF_REPORT_SETTING_DETAIL_ID_UNIQUE.Replace("@_@", whLoginID), paras).ToString() == "1");
        }

        public int DeleteUdfReportSettingDetail(List<string> reportID, string whLoginID)
        {
            int result = 0;
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                string sqlStr = this.SQL_DELETE_UDF_REPORT_SETTING_DETAIL.Replace("@_@", whLoginID);
                for (int j = 0; j < reportID.Count; j++)
                {
                    SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@REPORT_ID", reportID[j]) };
                    result += dataBase.ExecuteNonQuery(tran, CommandType.Text, sqlStr, paras);
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int DeleteUdfReportSettingDetail(List<string> reportID, List<string> lineID, string whLoginID)
        {
            int result = 0;
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                string sqlStr = this.SQL_DELETE_ONE_UDF_REPORT_SETTING_DETAIL.Replace("@_@", whLoginID);
                for (int j = 0; j < reportID.Count; j++)
                {
                    SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@REPORT_ID", reportID[j]), new SqlParameter("@LINE_ID", lineID[j]) };
                    result += dataBase.ExecuteNonQuery(tran, CommandType.Text, sqlStr, paras);
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int DeleteUdfReportSettingDetail(DataBase dataBase, DbTransaction tran, List<string> reportID, string whLoginID)
        {
            int result = 0;
            try
            {
                string sqlStr = this.SQL_DELETE_UDF_REPORT_SETTING_DETAIL.Replace("@_@", whLoginID);
                for (int j = 0; j < reportID.Count; j++)
                {
                    SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@REPORT_ID", reportID[j]) };
                    result += dataBase.ExecuteNonQuery(tran, CommandType.Text, sqlStr, paras);
                }
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            return result;
        }

        public int DeleteUdfReportSettingDetail(DataBase dataBase, DbTransaction tran, List<string> reportID, List<string> lineID, string whLoginID)
        {
            int result = 0;
            try
            {
                string sqlStr = this.SQL_DELETE_ONE_UDF_REPORT_SETTING_DETAIL.Replace("@_@", whLoginID);
                for (int j = 0; j < reportID.Count; j++)
                {
                    SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@REPORT_ID", reportID[j]), new SqlParameter("@LINE_ID", lineID[j]) };
                    result += dataBase.ExecuteNonQuery(tran, CommandType.Text, sqlStr, paras);
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        public DataSet GetAllUdfReportSettingDetail(string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = this.SQL_SELECT_ALL_UDF_REPORT_SETTING_DETAIL.Replace("@_@", whLoginID);
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@LANGUAGE", pubParasInfo.UserLanguage) };
            return DBHelper.ExecuteDataSet(CommandType.Text, sql, paras);
        }

        public DataSet GetAllUdfReportSettingDetail(DataBase dataBase, DbTransaction tran, string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = this.SQL_SELECT_ALL_UDF_REPORT_SETTING_DETAIL.Replace("@_@", whLoginID);
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@LANGUAGE", pubParasInfo.UserLanguage) };
            return dataBase.ExecuteDataSet(tran, CommandType.Text, sql, paras);
        }

        public UdfReportSettingDetailInfo GetUdfReportSettingDetailByID(string reportID, string lineID, string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = this.SQL_SELECT_ALL_UDF_REPORT_SETTING_DETAIL.Replace("@_@", whLoginID) + " WHERE REPORT_ID = @REPORT_ID AND LINE_ID = @LINE_ID  ";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@REPORT_ID", reportID), new SqlParameter("@LINE_ID", lineID), new SqlParameter("@LANGUAGE", pubParasInfo.UserLanguage) };
            UdfReportSettingDetailInfo UdfReportSettingDetailInfo = null;
            using (IDataReader reader = DBHelper.ExecuteReader(CommandType.Text, sql, paras))
            {
                if (reader.Read())
                {
                    UdfReportSettingDetailInfo = new UdfReportSettingDetailInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["REPORT_ID"].ToString(), (reader["LINE_ID"].ToString() != "") ? int.Parse(reader["LINE_ID"].ToString()) : 0, reader["CTRL_ID"].ToString(), reader["CTRL_LABEL"].ToString(), reader["CTRL_TYPE"].ToString(), reader["DEFAULT_VALUE"].ToString(), reader["PARAM_NAME"].ToString(), reader["IS_MUST_INPUT"].ToString(), reader["UDF1"].ToString(), reader["UDF2"].ToString(), reader["UDF3"].ToString(), reader["UDF4"].ToString(), reader["UDF5"].ToString(), reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : new DateTime(), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : new DateTime());
                }
            }
            return UdfReportSettingDetailInfo;
        }

        public UdfReportSettingDetailInfo GetUdfReportSettingDetailByID(DataBase dataBase, DbTransaction tran, string UdfReportSettingDetailID, string lineID, string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = this.SQL_SELECT_ALL_UDF_REPORT_SETTING_DETAIL.Replace("@_@", whLoginID) + " WHERE REPORT_ID = @REPORT_ID AND LINE_ID = @LINE_ID  ";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@REPORT_ID", UdfReportSettingDetailID), new SqlParameter("@LINE_ID", lineID), new SqlParameter("@LANGUAGE", pubParasInfo.UserLanguage) };
            UdfReportSettingDetailInfo UdfReportSettingDetailInfo = null;
            IDataReader reader = dataBase.ExecuteReader(tran, CommandType.Text, sql, paras);
            if (reader.Read())
            {
                UdfReportSettingDetailInfo = new UdfReportSettingDetailInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["REPORT_ID"].ToString(), (reader["LINE_ID"].ToString() != "") ? int.Parse(reader["LINE_ID"].ToString()) : 0, reader["CTRL_ID"].ToString(), reader["CTRL_LABEL"].ToString(), reader["CTRL_TYPE"].ToString(), reader["DEFAULT_VALUE"].ToString(), reader["PARAM_NAME"].ToString(), reader["IS_MUST_INPUT"].ToString(), reader["UDF1"].ToString(), reader["UDF2"].ToString(), reader["UDF3"].ToString(), reader["UDF4"].ToString(), reader["UDF5"].ToString(), reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : new DateTime(), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : new DateTime());
            }
            if (!reader.IsClosed)
            {
                reader.Close();
            }
            return UdfReportSettingDetailInfo;
        }

        public DataSet GetUdfReportSettingDetailByQueryList(List<string> sqlWhere, UdfReportSettingDetailQueryEntity UdfReportSettingDetailQuery, string whLoginID, PubParasInfo pubParasInfo)
        {
            string temp = this.SQL_SELECT_ALL_UDF_REPORT_SETTING_DETAIL.Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    temp = temp + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    temp = temp + " AND " + sqlWhere[i].ToString();
                }
            }
            if (!UdfReportSettingDetailQuery.IsGetAll)
            {
                temp = PagingHelper.GetPagingSQL(temp, UdfReportSettingDetailQuery.CurrentPage, UdfReportSettingDetailQuery.PageSize, UdfReportSettingDetailQuery.SortField, UdfReportSettingDetailQuery.SortDirection).Replace("@LANGUAGE", "''" + pubParasInfo.UserLanguage + "''");
            }
            else
            {
                temp = temp.Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'");
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, temp);
        }

        public DataSet GetUdfReportSettingDetailByQueryList(DataBase dataBase, DbTransaction tran, List<string> sqlWhere, UdfReportSettingDetailQueryEntity UdfReportSettingDetailQuery, string whLoginID, PubParasInfo pubParasInfo)
        {
            string temp = this.SQL_SELECT_ALL_UDF_REPORT_SETTING_DETAIL.Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    temp = temp + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    temp = temp + " AND " + sqlWhere[i].ToString();
                }
            }
            if (!UdfReportSettingDetailQuery.IsGetAll)
            {
                temp = PagingHelper.GetPagingSQL(temp, UdfReportSettingDetailQuery.CurrentPage, UdfReportSettingDetailQuery.PageSize, UdfReportSettingDetailQuery.SortField, UdfReportSettingDetailQuery.SortDirection).Replace("@LANGUAGE", "''" + pubParasInfo.UserLanguage + "''");
            }
            else
            {
                temp = temp.Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'");
            }
            return dataBase.ExecuteDataSet(tran, CommandType.Text, temp);
        }

        public List<UdfReportSettingDetailInfo> GetUdfReportSettingDetailListByID(string reportID, string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = this.SQL_SELECT_ALL_UDF_REPORT_SETTING_DETAIL.Replace("@_@", whLoginID) + " WHERE REPORT_ID = @REPORT_ID ORDER BY LINE_ID ";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@REPORT_ID", reportID), new SqlParameter("@LANGUAGE", pubParasInfo.UserLanguage) };
            List<UdfReportSettingDetailInfo> udfReportSettingDetailInfos = new List<UdfReportSettingDetailInfo>();
            UdfReportSettingDetailInfo udfReportSettingDetailInfo = null;
            using (IDataReader reader = DBHelper.ExecuteReader(CommandType.Text, sql, paras))
            {
                while (reader.Read())
                {
                    DateTime CS00002;
                    udfReportSettingDetailInfo = new UdfReportSettingDetailInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["REPORT_ID"].ToString(), (reader["LINE_ID"].ToString() != "") ? int.Parse(reader["LINE_ID"].ToString()) : 0, reader["CTRL_ID"].ToString(), reader["CTRL_LABEL"].ToString(), reader["CTRL_TYPE"].ToString(), reader["DEFAULT_VALUE"].ToString(), reader["PARAM_NAME"].ToString(), reader["IS_MUST_INPUT"].ToString(), reader["UDF1"].ToString(), reader["UDF2"].ToString(), reader["UDF3"].ToString(), reader["UDF4"].ToString(), reader["UDF5"].ToString(), reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : (CS00002 = new DateTime()), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : (CS00002 = new DateTime()));
                    udfReportSettingDetailInfos.Add(udfReportSettingDetailInfo);
                }
            }
            return udfReportSettingDetailInfos;
        }

        public List<UdfReportSettingDetailInfo> GetUdfReportSettingDetailListByID(DataBase dataBase, DbTransaction tran, string reportID, string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = this.SQL_SELECT_ALL_UDF_REPORT_SETTING_DETAIL.Replace("@_@", whLoginID) + " WHERE REPORT_ID = @REPORT_ID ORDER BY LINE_ID ";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@REPORT_ID", reportID), new SqlParameter("@LANGUAGE", pubParasInfo.UserLanguage) };
            List<UdfReportSettingDetailInfo> udfReportSettingDetailInfos = new List<UdfReportSettingDetailInfo>();
            UdfReportSettingDetailInfo udfReportSettingDetailInfo = null;
            using (IDataReader reader = dataBase.ExecuteReader(tran, CommandType.Text, sql, paras))
            {
                while (reader.Read())
                {
                    DateTime CS00002;
                    udfReportSettingDetailInfo = new UdfReportSettingDetailInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["REPORT_ID"].ToString(), (reader["LINE_ID"].ToString() != "") ? int.Parse(reader["LINE_ID"].ToString()) : 0, reader["CTRL_ID"].ToString(), reader["CTRL_LABEL"].ToString(), reader["CTRL_TYPE"].ToString(), reader["DEFAULT_VALUE"].ToString(), reader["PARAM_NAME"].ToString(), reader["IS_MUST_INPUT"].ToString(), reader["UDF1"].ToString(), reader["UDF2"].ToString(), reader["UDF3"].ToString(), reader["UDF4"].ToString(), reader["UDF5"].ToString(), reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : (CS00002 = new DateTime()), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : (CS00002 = new DateTime()));
                    udfReportSettingDetailInfos.Add(udfReportSettingDetailInfo);
                }
            }
            return udfReportSettingDetailInfos;
        }

        public int InsertUdfReportSettingDetail(UdfReportSettingDetailInfo UdfReportSettingDetailInfo, string whLoginID)
        {
            int result = 0;
            DataBase db = new DataBase();
            DbConnection conn = db.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                UdfReportSettingDetailInfo.WHID = whLoginID;
                SqlParameter[] paras = this.Set_UdfReportSettingDetail_Parameters(UdfReportSettingDetailInfo);
                if (paras != null)
                {
                    result += db.ExecuteNonQuery(tran, CommandType.Text, this.SQL_INSERT_UDF_REPORT_SETTING_DETAIL.Replace("@_@", whLoginID), paras);
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int InsertUdfReportSettingDetail(DataBase dataBase, DbTransaction tran, UdfReportSettingDetailInfo UdfReportSettingDetailInfo, string whLoginID)
        {
            int result = 0;
            try
            {
                UdfReportSettingDetailInfo.WHID = whLoginID;
                SqlParameter[] paras = this.Set_UdfReportSettingDetail_Parameters(UdfReportSettingDetailInfo);
                if (paras != null)
                {
                    result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_INSERT_UDF_REPORT_SETTING_DETAIL.Replace("@_@", whLoginID), paras);
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        private SqlParameter[] Set_UdfReportSettingDetail_Parameters(UdfReportSettingDetailInfo UdfReportSettingDetailInfo)
        {
            SqlParameter[] paramArray = new SqlParameter[] { new SqlParameter(this.WH_ID, SqlDbType.VarChar, 30), new SqlParameter(this.REPORT_ID, SqlDbType.VarChar, 30), new SqlParameter(this.LINE_ID, SqlDbType.Int, 4), new SqlParameter(this.CTRL_ID, SqlDbType.VarChar, 50), new SqlParameter(this.CTRL_LABEL, SqlDbType.VarChar, 100), new SqlParameter(this.CTRL_TYPE, SqlDbType.VarChar, 30), new SqlParameter(this.DEFAULT_VALUE, SqlDbType.VarChar, 200), new SqlParameter(this.PARAM_NAME, SqlDbType.VarChar, 100), new SqlParameter(this.IS_MUST_INPUT, SqlDbType.VarChar, 1), new SqlParameter(this.UDF1, SqlDbType.VarChar, 30), new SqlParameter(this.UDF2, SqlDbType.VarChar, 30), new SqlParameter(this.UDF3, SqlDbType.VarChar, 30), new SqlParameter(this.UDF4, SqlDbType.VarChar, 30), new SqlParameter(this.UDF5, SqlDbType.VarChar, 30), new SqlParameter(this.CREATED_BY, SqlDbType.VarChar, 0x12), new SqlParameter(this.UPDATED_BY, SqlDbType.VarChar, 0x12) };
            if (!string.IsNullOrEmpty(UdfReportSettingDetailInfo.WHID))
            {
                paramArray[0].Value = UdfReportSettingDetailInfo.WHID.Substring(0, UdfReportSettingDetailInfo.WHID.Length - 1);
            }
            else
            {
                paramArray[0].Value = DBNull.Value;
            }
            paramArray[1].Value = UdfReportSettingDetailInfo.ReportID;
            paramArray[2].Value = UdfReportSettingDetailInfo.LineID;
            paramArray[3].Value = UdfReportSettingDetailInfo.CtrlID;
            paramArray[4].Value = UdfReportSettingDetailInfo.CtrlLable;
            paramArray[5].Value = UdfReportSettingDetailInfo.CtrlType;
            paramArray[6].Value = UdfReportSettingDetailInfo.DefaultValue;
            paramArray[7].Value = UdfReportSettingDetailInfo.ParamName;
            paramArray[8].Value = UdfReportSettingDetailInfo.IsMustInput;
            paramArray[9].Value = UdfReportSettingDetailInfo.Udf1;
            paramArray[10].Value = UdfReportSettingDetailInfo.Udf2;
            paramArray[11].Value = UdfReportSettingDetailInfo.Udf3;
            paramArray[12].Value = UdfReportSettingDetailInfo.Udf4;
            paramArray[13].Value = UdfReportSettingDetailInfo.Udf5;
            paramArray[14].Value = UdfReportSettingDetailInfo.CreatedBy;
            paramArray[15].Value = UdfReportSettingDetailInfo.UpdatedBy;
            return paramArray;
        }

        public int UpdateUdfReportSettingDetail(UdfReportSettingDetailInfo UdfReportSettingDetailInfo, string whLoginID)
        {
            int result = 0;
            DataBase db = new DataBase();
            DbConnection conn = db.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                UdfReportSettingDetailInfo.WHID = whLoginID;
                SqlParameter[] paras = this.Set_UdfReportSettingDetail_Parameters(UdfReportSettingDetailInfo);
                if (paras != null)
                {
                    result += db.ExecuteNonQuery(tran, CommandType.Text, this.SQL_UPDATE_UDF_REPORT_SETTING_DETAIL.Replace("@_@", whLoginID), paras);
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int UpdateUdfReportSettingDetail(DataBase dataBase, DbTransaction tran, UdfReportSettingDetailInfo UdfReportSettingDetailInfo, string whLoginID)
        {
            int result = 0;
            try
            {
                UdfReportSettingDetailInfo.WHID = whLoginID;
                SqlParameter[] paras = this.Set_UdfReportSettingDetail_Parameters(UdfReportSettingDetailInfo);
                if (paras != null)
                {
                    result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_UPDATE_UDF_REPORT_SETTING_DETAIL.Replace("@_@", whLoginID), paras);
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }
    }
}

